package com.kittlen.springBootDemo.controller;

import com.kittlen.springBootDemo.entity.Author;
import com.kittlen.springBootDemo.entity.Result;
import com.kittlen.springBootDemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author kittlen
 * @version 1.0
 * @date 2020/12/7 11:51
 */
@RestController
@RequestMapping("hello")
public class HelloController {

    @Value("${projectName}")
    public String projectName;

    @Resource
    public UserService userService;

//    //添加注解
//    @Autowired
//    public Author author;
    //与对象冲突,所以注掉

//    @RequestMapping("hi")
//    public Result hello(){
//        Result result=new Result();
//        result.setData(projectName+author.toString());
//        return  result;
//    }

    @RequestMapping("getUser")
    public Result getUser(@RequestParam(name = "id",defaultValue = "")String id){
        Result result=new Result();
        if("".equals(id)){
            result.setData(userService.selectUser());
        }else{
            result.setData(userService.selectById(id));
        }
        return result;
    }

    @RequestMapping("getDepartmentByDao")
    public Result getUserByDao(){
        Result result=new Result();
        result.setData(userService.selectDepartment());
        return result;
    }
}
